{include file="public/header"/}
<style>
    html,
    body {
        background-color: #fff;
    }

    .editPopupBox {
        width: 100%;
        height: auto;
        padding: 20px 5px;
        box-sizing: border-box;
    }

    body {
        background: #fff;
    }

    .manage-wrap {
        margin: 20px auto 10px;
        width: 450px;
    }

    .manage-wrap .ui-input {
        width: 150px;
        font-size: 14px;
    }

    .mod-form-rows .tips {
        color: #555;
        font-size: 14px;
    }

    .descript {
        display: inline-block;
        margin-left: 10px;
    }

    .ui-icon-none {
        display: inline-block;
        width: 20px;
        height: 20px;
        vertical-align: middle;
    }

    .ui-icon {
        display: inline-block;
        width: 20px;
        height: 20px;
        vertical-align: middle;
    }

    .mod-form-rows .label-wrap {
        width: 92px;
        text-align: right;
    }

    .manage-wrap .rateNum {
        width: 60px;
        margin-left: 10px;
    }

    .row-item-btn {
        margin-bottom: 15px;
        zoom: 1;
    }
</style>
<div id="manage-wrap" class="manage-wrap editPopupBox">
    <form id="manage-form" action="#">
        <ul class="mod-form-rows">
            <li class="row-item">
                <div class="label-wrap"><a class="ui-icon-none"></a><span class="red spe_red">*</span><label
                        for="baseUnit">基本单位：</label></div>
                <div class="ctn-wrap"><input type="text" name="pname" value="{$info.name}" class="ui-input" id="baseUnit"><span
                        class="descript">基本单位应为最小度量单位</span></div>
            </li>
        </ul>
        <ul class="mod-form-rows" id="mod-form-rows">
            {volist name="info.son" id="vo"}
            <li class="row-item">
                <div class="label-wrap"><a class="ui-icon ui-icon-trash" title="删除"></a><label for="group"
                        id="deputyUnitLabel">副单位{$key + 1}：</label></div>
                <div class="ctn-wrap"><input type="text" name="name[]" value="{$vo.name}" class="ui-input" id="deputyUnit"><span
                        class="descript">=</span><input type="text" name="rate[]" value="{$vo.rate}" class="ui-input rateNum"
                        id="deputyUnitRate"><span class="descript baseUnitLabel" id="baseUnitLabel"></span></div>
            </li>
            {/volist}
        </ul>
        <input type="hidden" name="id" value="{$info.id}">
        <input type="button" class="ui-btn" id="addDeputy" value="增加单位">
    </form>
</div>
<script>
    $("#btn-add").click(function () {
        $.ajax({
            type: 'POST',
            url: "save.html",
            data: $("#manage-form").serialize(),
            dataType: "json",
            async: false,
            error: function (request) {
                alert("发送请求失败！");
            },
            success: function (data) {
                if (data.status == 1) {
                    alert(data.msg);
                } else {
                    alert(data.msg);
                }

            }
        });
    });

    $(function () {
        // 增加副单位
        $("#addDeputy").click(function (a) {
            var t = ['<li class="row-item">', '<div class="label-wrap"><a class="ui-icon ui-icon-trash" title="删除"></a><label for="group" id="deputyUnitLabel">副单位1：</label></div>', '<div class="ctn-wrap">', '<input type="text" name="name[]" class="ui-input" id="deputyUnit">', '<span class="descript">=</span>', '<input type="text" name="rate[]" class="ui-input rateNum" id="deputyUnitRate">', '<span class="descript baseUnitLabel" id="baseUnitLabel">' + $("#baseUnit").val() + "</span>", "</div>"].join("");
            $("#mod-form-rows").append(t);
            var e = $("#mod-form-rows").find("li").length,
                n = 0;
            for (i = 0; i < e; i++) {
                var r = "副单位" + ++n + "：";
                $("#mod-form-rows >li").eq(i).find("label").html(r)
            }
        });
        // 删除副单位
        $("#manage-wrap").on("click", ".ui-icon-trash", function (a) {
            a.preventDefault(), $(this).parent("div").parent("li").remove();
            var t = $("#mod-form-rows").find("li").length,
                e = 0;
            for (i = 0; i < t; i++) {
                var n = "副单位" + ++e + "：";
                $("#mod-form-rows >li").eq(i).find("label").html(n)
            }
        })
    });
</script>
{include file="public/footer"/}